home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
cenvid
/
move.cmm
< prev
next >
Wrap
Text File
|
1995-10-01
|
3KB
|
112 lines
/*
* move.cmm
*
* This .CMM file implements a Move command which combines the functionality
* of Move and Rename.
*/
#include "Netware.lib"
usage()
{
printf("Use the MOVE command to change a file's name or directory.\n");
printf("The contents of the file(s) remains unchanged. RENAME is a\n");
printf("valid synonym for MOVE.\n");
printf("Syntax:\n");
printf(" MOVE [drive:][path]filename1 [drive:][path]filename2\n");
printf("where:\n");
printf(" drive:/path/filename1 Specifies the file to rename.\n");
printf(" drive:/path/filename2 Specifies the new filename.\n");
exit(EXIT_FAILURE);
}
/* ---------------------------------------------------------------------- */
//
// Move a file to the given destination.
//
move_file(source,dest)
{
if( rename(source,dest) )
{
printf("Unable to rename file \"%s\" to \"%s\".\n",source,dest);
}
}
main(argc,argv)
{
if( argc!=3 ) usage();
source = argv[1];
target = argv[2];
// First we get the source files to transfer
orig = Directory(source);
if( orig==NULL )
{
printf("No such file or directory \"%s\"\n",source);
exit(EXIT_FAILURE);
}
// Get the destination. It may either be a directory, in which case we
// move all the files into it. It may be a filename, in which case we
// can only have once source file and we move it to the new one. Otherwise,
// it contains wildcards and we do a block move hacking the filename as
// we go.
if( strchr(target,'*') || strchr(target,'?') )
{
printf("Wildcard destinations not yet implemented.\n");
exit(EXIT_FAILURE);
}
if( !strcmp(target,".") )
{
dest = NULL;
} else {
dest = Directory(target);
if( target[strlen(target)-1]=='/' || target[strlen(target)-1]=='\\' )
{
target[strlen(target)-1] = '\0';
dest = Directory(target);
}
if( dest==NULL )
{
// First check to see if he specified a volume name.
if( !(isalpha(target[0]) && target[1]==':' &&
(target[2]=='\0' || target[2]=='/' || target[2]=='\\')) )
{
if( GetArraySpan(orig)>0 )
printf("There is no directory named \"%s\".\n",target);
}
} else {
if( GetArraySpan(dest)!=0 )
{
printf("You cannot move a file to multiple destinations.\n");
exit(EXIT_FAILURE);
}
}
}
if( dest==NULL || dest[0].attrib & _A_SUBDIR )
{
for( i=0;i<=GetArraySpan(orig);i++ )
{
filestruct = SplitFileName(orig[i].name);
if( dest==NULL && strcmp(target,".") )
{
strcpy(tmpname,target);
} else {
sprintf(tmpname,"%s%c%s%s",dest?dest[0].name:target,
defined(_NWNLM_)?'/':'\\',filestruct.name,filestruct.ext);
}
move_file(orig[i].name,tmpname);
}
} else {
printf("Target file already exists.\n");
exit(EXIT_FAILURE);
}
}